let db = require('../db/index')

exports.all = (req, res) => {        //获取info表全部数据
    var sql = 'select * from event where event_name = ?'
    db.query(sql, [req.query.id], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
            
        }
        res.send(data)
    })

}

exports.add = (req, res) => {        //向info表添加数据
    var sql = 'insert into event (event_type,event_mark,event_describe,event_carnum,event_name,event_level) values (?,?,?,?,?,?)'
    db.query(sql, [req.query.event_type, req.query.event_mark, req.query.event_describe, req.query.event_carnum, req.query.event_name, req.query.event_level], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        if(data.affectedRows > 0) {
            res.send({
              status: 200,
              message: 'success'
            })
        }else{
            res.send({
              status: 202,
              message: 'error'
            })
        }
    })
}




exports.update = (req, res) => {        //通过id更新数据
    var sql = 'update event event_addr = ?, event_status = ?, event_level = ? where event_id = ?'
    db.query(sql, [req.query.event_addr, req.query.event_status, req.query.event_level], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        if(data.changedRows > 0) {
          res.send({
            status: 200,
            message: 'success'
          })
        }else{
          res.send({
            status: 202,
            message: 'error'
          })
        }
    })
}
